package com.fastadmin.mapper.impl;

import com.fastadmin.pojo.FastParam;
import com.fastadmin.pojo.GongGao;
import com.xphsc.easyjdbc.EasyJdbcTemplate;
import com.xphsc.easyjdbc.page.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.Collections;

@Repository
public class GongGaoMapper extends BaseMapper {

    @Autowired
    EasyJdbcTemplate easyJdbcTemplate;

    public GongGao findById(String ids) {
        return easyJdbcTemplate.getByPrimaryKey(GongGao.class, ids);
    }

    public PageInfo<GongGao> findByFastParam(FastParam fastParam) {
        String sql = fastParam.getSql("t_gonggao");
        return this.easyJdbcTemplate.findByPage(sql, GongGao.class, fastParam.offset, fastParam.limit);
    }

    public void deleteById(String ids) {
        this.easyJdbcTemplate.deleteByIds(GongGao.class, Collections.singleton(ids));
    }

    public void update(GongGao gongGao) {
        gongGao.setUpdate_time(timestamp());
        this.easyJdbcTemplate.update(gongGao);
    }

    public void save(GongGao gongGao) {
        gongGao.setCreate_time(timestamp());
        gongGao.setUpdate_time(timestamp());

        this.easyJdbcTemplate.insertKey(gongGao);
    }
}
